#include "register/global_enum/register_global_enum.h"
#include "quickjs/env.h"
#include "quickjs/quickjs.h"

void register_global_enum() {
    JSValue global_obj = JS_GetGlobalObject(ctx);
    {%- for enum in enums %}
    {%- if '.' not in enum['name'] %}
	JSValue {{enum['name']}}_obj = JS_NewObject(ctx);
        {%- for value in enum['values'] %}
	JS_SetPropertyStr(ctx, {{enum['name']}}_obj, "{{value['name']}}", JS_NewInt64(ctx, {{value['value']}}));
        {%- endfor %}
	JS_SetPropertyStr(ctx, global_obj, "{{enum['name']}}", {{enum['name']}}_obj);
    {% else %}
    {% set enum_name = enum['name'].split('.')[1]  %}
    JSValue {{enum_name}}_obj = JS_NewObject(ctx);
        {%- for value in enum['values'] %}
	JS_SetPropertyStr(ctx, {{enum_name}}_obj, "{{value['name']}}", JS_NewInt64(ctx, {{value['value']}}));
        {%- endfor %}
	JS_SetPropertyStr(ctx, global_obj, "{{enum_name}}", {{enum_name}}_obj);
    {% endif %}
    {%- endfor %}
}